package com.qm.struts.friendspace;

import java.util.List;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.qm.hibernate.TblogDAO;
import com.qm.hibernate.TpostDAO;
import com.qm.hibernate.Tuser;
import com.qm.hibernate.TuserDAO;

public class HisInfoAction implements Action{

	private Integer id;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	@Override
	public String execute() throws Exception {
		
		TuserDAO ud = new TuserDAO();
		ActionContext ctx = ActionContext.getContext();
		Tuser friend = (Tuser)ctx.getSession().get("friend");
		Tuser user = (Tuser)ctx.getSession().get("user");
		List<Tuser> l3 = ud.findFriends(friend.getId());
		boolean friendRelation = false;
		for (int i = 0;i < l3.size();i++)
		{
			if (user.getId().equals(l3.get(i).getId()))
			{
				friendRelation = true;
				break;
			}
		}
		
		if ("self".equals(friend.getPermission())) return ERROR;
		if ("friends".equals(friend.getPermission())&&!friendRelation) return ERROR;
			
		TblogDAO bd = new TblogDAO();
		List l = bd.findByProperty("tuser.id", getId());
		ctx.getSession().put("hisBlogs", l);
		return SUCCESS;
	}

}
